package com.snake.springboot.custom.service.impl.goods;

import com.snake.springboot.custom.api.model.goods.CustStryGoodsDetailModel;
import com.snake.springboot.custom.api.response.goods.CustStryGoodsDetailRsp;
import com.snake.springboot.custom.api.response.goods.CustStryGoodsRsp;
import com.snake.springboot.custom.api.service.goods.CustStryGoodsDetailService;
import com.snake.springboot.custom.dao.mybatis.entity.goods.CustStryGoodsDetailDO;
import com.snake.springboot.custom.dao.mybatis.mappers.goods.CustStryGoodsDetailMapper;
import org.snake.common.utils.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CustStryGoodsDetailServiceImpl implements CustStryGoodsDetailService{

    @Autowired
    private CustStryGoodsDetailMapper custStryGoodsDetailMapper;

    @Override
    public void insertBatch(List<CustStryGoodsDetailModel> models) {
        List<CustStryGoodsDetailDO> detailDOS = ListUtils.copy(models, CustStryGoodsDetailDO.class);
        custStryGoodsDetailMapper.batchInsert(detailDOS);
    }

    @Override
    public void queryDetailList(List<CustStryGoodsRsp> rspList) {
        if(ListUtils.isEmpty(rspList)){
            return;
        }
        List<String> ids = rspList.stream().map(CustStryGoodsRsp::getCustStryGoodsId).collect(Collectors.toList());
        List<CustStryGoodsDetailDO> detailDOS = custStryGoodsDetailMapper.queryDetailList(ids);
        List<CustStryGoodsDetailRsp> goodsDetailList = ListUtils.copy(detailDOS, CustStryGoodsDetailRsp.class);
        for (CustStryGoodsRsp rsp : rspList) {
            rsp.setDetailList(goodsDetailList.stream().filter(detail -> detail.getCustStryGoodsId().equals(rsp.getCustStryGoodsId())).collect(Collectors.toList()));
        }
    }
}
